package mystackdemo;

import java.util.ArrayList;
import java.util.Arrays;

public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack() {
        elem = new int[10];
    }

    public void push(int val) {
        if(isFull()) {
            elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize] = val;
        usedSize++;
    }
    private boolean isFull() {
        return usedSize == elem.length;
    }
    public void pop() {
        if(isEmpty()) {
            return;
        }
        int oldValue = elem[usedSize-1];
        usedSize--;
        System.out.println(oldValue);
    }
    private boolean isEmpty() {
        if(usedSize == 0) {
            return true;
        }
        return false;
    }
    public void peek() {
        if(usedSize == 0) {
            return;
        }
        System.out.println(elem[usedSize-1]);
    }
}
